package com.mgr.controller;

import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.mgr.model.Accounts;
import com.mgr.service.AccountService;

@Controller
public class InternalTransferController1 {

	@Autowired
	private AccountService accountService;

	private ResourceBundle rb = ResourceBundle
			.getBundle("com.mgr.messages.errorMessage");

	@RequestMapping("internaltransfer")
	public ModelAndView setFormTransfer(HttpSession session,
			Map<String, Object> map) {
		session.setAttribute("countTran",0);
		ModelAndView modelAndView = new ModelAndView(
				"internaltransaction1.tile");
		if (session.getAttribute("user") == null) {
			modelAndView.setViewName("login");
		} else
			try {
				String st = session.getAttribute("user").toString();
				int custId = Integer.parseInt(st);
				List<Accounts> lstAcc = accountService
						.getAccountByCustId(custId);
				if (lstAcc.isEmpty()) {
					modelAndView.addObject("err", rb.getObject("accEmpty"));
					modelAndView.setViewName("welcome.tile");
				} else {
					map.put("accountList",
							accountService.getAccountByCustId(custId));
				}
			} catch (Exception e) {
				System.out.println("Error convert String to number");
			}
		return modelAndView;
	}
}